package com.offcn.service;

import com.netflix.ribbon.proxy.annotation.Hystrix;
import com.offcn.dao.UserDao;
import com.offcn.entity.Movie;
import com.offcn.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

import java.util.HashMap;
import java.util.Map;

@Service
public class UserService {
    @Autowired
    private UserDao userDao;
   /* @Autowired
    private RestTemplate restTemplate;*/

    @Autowired
    private MovieServiceFeign movieServiceFeign;


    public User getUser(Integer id){
        return userDao.getUser(id);
    }

    //买票
    public Map<String,Object> buyMovie(Integer id){
        Map map = new HashMap();
        //根据id查询用户
        User user = userDao.getUser(id);
        map.put("user",user);
        // Movie movie = restTemplate.getForObject("http://PROVIDERMOVIE/movie", Movie.class);
        //查看电影票
        Movie movie = movieServiceFeign.getMovie(); //feign的远程调用
        map.put("movie",movie);
        return map;
    }
}
